<?php

namespace App\Http\Common\pools\redis;

use Illuminate\Redis\RedisManager;
use Illuminate\Support\Arr;
use Swoole\ConnectionPool;

class RedisConfigPool extends ConnectionPool
{
    public function __construct(int $size = self::DEFAULT_SIZE)
    {
        $config = config('database.redis');
        parent::__construct(function () use ($config) {
            $manager = new RedisManager(app(), Arr::pull($config, 'client', 'phpredis'), $config);
            return $manager->client();
        }, $size);
    }

    public function put($connection): void
    {
       parent::put($connection);
    }

    public function get(float $timeout = -1): \Redis
    {
        return parent::get($timeout);
    }
}
